package com.matt.domain;

import com.matt.foundation.retention.FieldMeta;
import com.matt.foundation.model.Domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.procedure.spi.ParameterRegistrationImplementor;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * *******************************
 * description:合同
 * Created by Ron.
 * form com.matt
 * on 2018/6/13
 * *******************************
 */
@Entity
@Table(name = "contract")
@Data
@EqualsAndHashCode(callSuper = true)
public class Contract extends Domain {

    @FieldMeta(name = "合同名称")
    @Column(columnDefinition = "varchar(50) COMMENT '合同名称'")
    private String name;

    @FieldMeta(name = "合同编码")
    @Column(columnDefinition = "varchar(50) COMMENT '合同编码'")
    private String code;

    @FieldMeta(name = "开始时间")
    @Column(columnDefinition = "datetime DEFAULT NOW() COMMENT '开始时间'")
    private Date beginDate;

    @FieldMeta(name = "合同状态")
    @Column(columnDefinition = "int default 0  COMMENT ' 0：未开始 1。正常， 2：已终止, 3：已结束  4:待补款'")
    private Integer status = 1;

    @FieldMeta(name = "合同状态Val")
    @Column(columnDefinition = "varchar(50) COMMENT ' 0：未开始 1。正常， 2：已终止, 3：已结束 4:待补款'")
    private String statusVal;

    @FieldMeta(name = "结束时间")
    @Column(columnDefinition = "datetime COMMENT '结束时间'")
    private Date endDate;

    @FieldMeta(name = "签单时间")
    @Column(columnDefinition = "datetime COMMENT '签单时间'")
    private Date signDate;

    @FieldMeta(name = "付款方式类型")
    @Column(columnDefinition = "int default 0 COMMENT '付款方式 1:现金 2:刷卡 3:银行转账 4:支付宝 5:微信 6:其他'")
    private Integer payChannel = 1;

    @FieldMeta(name = "付款方式文本")
    @Column(columnDefinition = "varchar(50) COMMENT '线下支付方式值'")
    private String payChannelVal;

    @FieldMeta(name = "总金额")
    @Column(columnDefinition = "decimal(12, 2) COMMENT '总金额'")
    private BigDecimal totalAmount = BigDecimal.ZERO;

    //付款状态
    @FieldMeta(name = "付款状态")
    @Column(columnDefinition = "int(3) default 0 COMMENT '0：未付清 1：已付清'")
    private Integer payStatus = 0;

    //付款状态
    @FieldMeta(name = "付款状态")
    @Column(columnDefinition = "varchar(50) COMMENT '0：未付清 1：已付清'")
    private String payStatusVal = "未付清";

    @FieldMeta(name = "付款类型")
    @Column(columnDefinition = "int default 0 COMMENT '付款类型 1:定金 2:全款 3:线上收款 '")
    private Integer payType = 1;

    @FieldMeta(name = "付款类型Val")
    @Column(columnDefinition = "varchar(50) COMMENT '付款类型 1:线下定金 2:线下全款 3:线上收款'")
    private String payTypeVal;

    @FieldMeta(name = "实付金额")
    @Column(columnDefinition = "decimal(12, 2) COMMENT '已支付金额'")
    private BigDecimal practicalAmount = BigDecimal.ZERO;

    @FieldMeta(name = "附件地址")
    @Column(columnDefinition = "longtext COMMENT '附件地址'")
    private String attachmentUrl;

    @FieldMeta(name = "客户id")
    @Column(columnDefinition = "varchar(32) COMMENT '客户id'")
    private String clienteleId;

    @FieldMeta(name = "园区id")
    @Column(columnDefinition = "varchar(32) COMMENT '所属园区'")
    private String areaId;

    @FieldMeta(name = "合同类型")
    @Column(columnDefinition = "int default 1 COMMENT '合同类型 1:托班，2：早教，3：托班+早教，4：其它'")
    private Integer type = 1;

    @FieldMeta(name = "备注")
    @Column(columnDefinition = "longtext COMMENT '备注'")
    private String remark;

    @FieldMeta(name = "负责人Id")
    @Column(columnDefinition = "varchar(32) COMMENT '员工ID'")
    private String staffId;

    @FieldMeta(name = "最后更新时间")
    @Column(columnDefinition = " datetime DEFAULT NOW() COMMENT '最后更新时间' ")
    private Date lastModified;

    @FieldMeta(name = "最后更新人")
    @Column(columnDefinition = "varchar(32) COMMENT '最后更新人'")
    private String lastModifiedId;

    @FieldMeta(name = "中止原因")
    @Column(columnDefinition = "varchar(255) COMMENT '中止原因'")
    private String breakDownReason;

    @FieldMeta(name = "中止备注")
    @Column(columnDefinition = "longtext COMMENT '中止备注'")
    private String breakDownRemark;

    @FieldMeta(name = "最终回款时间")
    @Column(columnDefinition = "datetime COMMENT '最终回款时间'")
    private Date paidDate;

    //用于统计
    @Column(columnDefinition = "bit default 0 COMMENT '是否是续约合同 0:不是，1:是'")
    private Boolean isRenewal = false;

    @Column(columnDefinition = "int default 1 COMMENT '合同渠道 0:原教务导入， 1：crm新建'")
    private Integer fromChannel = 1;

    //冗余字段
    @FieldMeta(name = "负责人")
    @Column(columnDefinition = "varchar(100) COMMENT '创建人姓名'")
    private String staffName;

    @Transient
    private Integer clienteleStatus; //跟进状态

    @Transient
    private Integer signStatus; //成交状态

    @Transient
    private BigDecimal contractDay = BigDecimal.ZERO; //合同天数

    @Transient
    private BigDecimal monthPrice = BigDecimal.ZERO; //月单价

    @Column(columnDefinition = "int default 10 COMMENT  '剩余可请假延长合同天数' ")
    private Integer surplusLeaveDay = 10;
}
